package com.byt.xmxb.model;

import com.byt.base.model.BaseModel;
import com.byt.common.Constants;
import com.byt.common.view.finder.entity.Province;
import com.byt.netapi.bean.ResponseBean;
import com.byt.netapi.exception.ExceptionHandle;
import com.byt.netapi.observer.BaseObserver;
import com.byt.xmxb.api.MainApi;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;

public class ProvinceModel extends BaseModel<ArrayList<Province>> {

    public ProvinceModel() {

    }

    @Override
    protected String getCachedPreferenceKey() {
        return Constants.ADDRESS_CASHE_XMXB;
    }

    @Override
    protected Type getTClass() {
        return new TypeToken<ArrayList<Province>>(){}.getType();
    }

    @Override
    public void refresh() {
        load();
    }

    @Override
    protected void load() {
        MainApi.getInstance().getAreList(new BaseObserver<ResponseBean<ArrayList<Province>>>(this) {
            @Override
            public void onError(ExceptionHandle.ResponeThrowable e) {
                loadFail(e.getCause().getMessage());
            }

            @Override
            public void onNext(ResponseBean<ArrayList<Province>> listResponseBean) {
                loadSuccess(listResponseBean.getData());
            }
        });
    }


}
